package com.exam.hellohass.utils;

import java.io.IOException;
import java.net.ContentHandler;
import java.util.ArrayList;
import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.exam.hellohass.bean.MyObject;
import com.exam.hellohass.data.ContenData;


public class JsoupForContent {
	static String content = "";
	static String content_1 = "";
	static String content_2 = "";
	
	public static List<MyObject> getItemList(String url){
		List<MyObject> itemList = new ArrayList<MyObject>();
		String abs = url;
		try {
			Document doc = Jsoup.connect(url)
					.data("jquery", "java").userAgent("hellohass")
					.cookie("auth", "token").timeout(50000).get();
			
			content = doc.toString();
			
			Document doc1 = Jsoup.parse(content);
//			Elements divcontent = doc1.getElementsByClass("contentdiv");
			Elements divcontent = doc1.select("div#sliderB");
			content_1 = divcontent.toString();
			
			Document doc2 = Jsoup.parse(content_1,abs);
			Elements texts = doc2.getElementsByTag("li");
			int i =0 ;
			for (Element element : texts) {
				i++;
				if (i<=10) {
					String contentUrl = element.getElementsByTag("a").attr("abs:href");
					String text = element.getElementsByTag("a").text();
					MyObject myObject = new MyObject(text, contentUrl);
					myObject.setImg(text);
					myObject.setImgUrl(contentUrl);
					itemList.add(myObject);
				}else {
					break;
				}
				
			}
			
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return itemList;
		
	}
	
//	public static List<String> getConent(String url) {
//		List<String> mList = new ArrayList<String>();
//		String abs = url;
//		try {
//			Document doc = Jsoup.connect(url)
//					.data("jquery", "java").userAgent("hellohass")
//					.cookie("auth", "token").timeout(50000).get();
//			
//			content = doc.toString();
//			
//			Document doc1 = Jsoup.parse(content);
//			Elements divcontent = doc1.select("div#sliderB");
//			content_1 = divcontent.toString();
//			
//			Document doc2 = Jsoup.parse(content_1,abs);
//			Elements texts = doc2.getElementsByTag("li");
//			int i = 0;
//			for (Element element : texts) {
//				String text = element.getElementsByTag("a").text();
//				i++;
//				if (i<=10) {
//					mList.add(text);
//				}else{
//					break;
//				}
//			}
//			
//			
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//
//		return mList;
//	}
}
